﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.tutorial.chapter {
    import flash.utils.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.events.windows.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.controllers.startup.*;
    import net.wooga.pets.views.tutorial.*;

    public class TutorialKindergartenMediator extends TutorialMediator {

        private var _localMapping:Dictionary;

        public function TutorialKindergartenMediator():void{
            this._localMapping = new Dictionary();
            this._localMapping[TutorialModel.KINDERGARTEN_START_TUTORIAL] = this.onBuildKindergartenTutorial;
            this._localMapping[TutorialModel.KINDERGARTEN_CLICK_ON_SHOP] = this.onClickShopForKindergarten;
            this._localMapping[TutorialModel.KINDERGARTEN_CHOOSE_ROOM] = this.onChooseKindergarten;
            this._localMapping[TutorialModel.KINDERGARTEN_PLACE_ROOM] = this.onPlaceKindergarten;
            this._localMapping[TutorialModel.KINDERGARTEN_BABY_WALK_IN] = this.onBabyWalkIn;
            this._localMapping[TutorialModel.KINDERGARTEN_FINISH_TUTORIAL] = this.onFinish;
        }
        override public function onRegister():void{
            super.onRegister();
        }
        override protected function onStateChange(_arg1:GameEvent=null):void{
            super.onStateChange(_arg1);
            var _local2:Function = this._localMapping[tutorialModel.state];
            if (_local2 != null){
                _local2();
            };
        }
        public function onBuildKindergartenTutorial():void{
            eventMap.mapListener(eventDispatcher, EventConstants.BUBBLE_CLOSED, mapBubbleClosed);
            tutorial.showClickBlocker();
            tutorial.hideSpotlight();
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
        }
        public function onClickShopForKindergarten():void{
            roomSlotsModel.tempAvailableRoomSlots = 1;
            dispatch(new UserModelEvent(UserModelEvent.ON_MODEL_CHANGED));
            centerGameView(GameViewModel.SCALE_4X4);
            eventMap.unmapListener(eventDispatcher, EventConstants.BUBBLE_CLOSED, mapBubbleClosed);
            mapEvent(EventConstants.ON_OPEN_CUSTOMIZE_MENU, TutorialModel.KINDERGARTEN_CHOOSE_ROOM);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_kindergarten_open_shop");
            focusShopButton();
        }
        public function onChooseKindergarten():void{
            dispatch(new InfoEvent(EventConstants.SELECT_SHOP_CATEGORY, null, {category:"rooms"}));
            roomSlotsModel.tempAvailableRoomSlots = 1;
            dispatch(new UserModelEvent(UserModelEvent.ON_MODEL_CHANGED));
            dispatch(new InfoEvent(EventConstants.SET_BUILD_CANCELATION, null, false));
            centerGameView(GameViewModel.SCALE_4X4);
            eventMap.unmapListener(eventDispatcher, EventConstants.BUBBLE_CLOSED, mapBubbleClosed);
            mapEvent(EventConstants.ON_START_DRAGGING_CUSTOMIZE_ITEM, TutorialModel.KINDERGARTEN_PLACE_ROOM);
            eventMap.mapListener(eventDispatcher, EventConstants.TRY_TO_CANCEL_BUILDMODE, mapTryToCancel);
            if (tutorialModel.kindergartenShopItemPosition){
                sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_kindergarten_choose");
                tutorial.showFocusArrow((tutorialModel.kindergartenShopItemPosition.x - 10), (tutorialModel.kindergartenShopItemPosition.y - 170));
                tutorial.showClickBlocker((tutorialModel.kindergartenShopItemPosition.x + 30), (tutorialModel.kindergartenShopItemPosition.y + 30), 0.3);
                tutorial.showSpotlight((tutorialModel.kindergartenShopItemPosition.x + 30), (tutorialModel.kindergartenShopItemPosition.y + 30), 0.5);
            } else {
                tutorial.hideFocusArrow();
                tutorial.showClickBlocker();
                tutorial.hideSpotlight();
                setTimeout(this.onChooseKindergarten, 1000);
            };
        }
        public function onPlaceKindergarten():void{
            roomSlotsModel.tempAvailableRoomSlots = 0;
            mapEvent(EventConstants.CREATE_BABY_VIEW, TutorialModel.KINDERGARTEN_BABY_WALK_IN);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_kindergarten_build");
            tutorial.hideFocusArrow();
            tutorial.hideClickCatcher();
            tutorial.hideSpotlight();
            l(("roomSlotsModel.getNumberOfOccupiedSlots(): " + roomSlotsModel.getNumberOfOccupiedSlots()));
            if (roomSlotsModel.getNumberOfOccupiedSlots() >= 18){
                enableControls();
                dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
            };
        }
        public function onBabyWalkIn():void{
            triggerNewState(TutorialModel.KINDERGARTEN_FINISH_TUTORIAL, 300);
            var _local1:InfoEvent = (lastEvent as InfoEvent);
            var _local2:IBaby = (_local1.info as IBaby);
            _local2.moveToNextTarget(GameConstants.TYPE_KINDERGARTEN);
        }
        public function onBabyWalkToKindergarten():void{
            var _local1:InfoEvent = (lastEvent as InfoEvent);
            var _local2:IBaby = (world.getActor(_local1.id) as IBaby);
            l(("baby: " + _local2));
            _local2.moveToNextTarget(GameConstants.TYPE_KINDERGARTEN);
            triggerNewState(TutorialModel.KINDERGARTEN_FINISH_TUTORIAL, 300);
        }
        public function onFinish():void{
            roomSlotsModel.tempAvailableRoomSlots = 0;
            dispatch(new InfoEvent(EventConstants.SET_BUILD_CANCELATION, null, true));
            onRemoveOverlay();
            gameStateModel.state = GameStateModel.STATE_GAME_RUNNING;
            enableControls();
            dispatch(new InfoEvent(EventConstants.CHECK_FOUNTAIN_TUTORIAL, null, {state:TutorialModel.FOUNTAIN_START_TUTORIAL}));
        }

    }
}//package net.wooga.pets.views.tutorial.chapter 
